<!--  -->
<template>
  <div class='recommend'>
    <!--        头部-->
    <head-top></head-top>
    <!--    <div style="width: 100%;height: 120px;"></div>-->
    <div class="vantTabs">
      <van-tabs sticky title-active-color="#fbef1a" @click="clickTitle" line-width="0px" line-height="0"
                title-inactive-color="#9a9a9a">
        <van-tab v-for="(item,index) in taskList" :key="index">
          <template #title>{{ item.title }}</template>
          <div class="search" v-if="currentTag == 0">
            <div class="searchpd">
              <input placeholder="请输入被推荐人微信" v-model="page.weixin"/>
              <p @click="query">查询</p>
            </div>
          </div>
          <div style="width: 100%;height: 147px;"></div>
          <div class="taskcon">
            <div class="taskconmsg" v-if="taskconFlag">
              <div class="title">{{payment.surplusMessage}}</div>
              <van-list
                      v-model="loading"
                      :finished="finished"
                      finished-text="没有更多了"
                      :immediate-check="false"
                      @load="onLoad"
              >
              <div class="item" v-for="item in list">
                <ul>
                  <li>
                    <div>提交时间：</div>
                    <div class="reslut">{{ item.createTime }}</div>
                  </li>
                  <li>
                    <div>微信号：</div>
                    <div class="reslut">{{ item.weixin }}</div>
                  </li>
                  <li>
                    <div>电话：</div>
                    <div class="reslut">{{ item.phone }}</div>
                  </li>
                  <li>
                    <div>支付单号：</div>
                    <div class="reslut">{{ item.orderNumber }}</div>
                  </li>
                  <li>
                    <div>状态：</div>
                    <div class="reslut">{{ item.orderAuditStatus }}</div>
                  </li>
                </ul>
              </div>
              </van-list>
            </div>

            <div class="editorCon" v-else>
              <van-form validate-first @failed="onFailed">
                <div class="formItem">
                  <div class="formItemBg">
                    <p class="nameTitle">真实姓名</p>
                    <van-field
                        v-model="form.realname"
                        name="pattern"
                        placeholder="请输入"
                        :rules="[{required: true,message: '请输入真实姓名' }]"
                    />
                  </div>
                </div>
                <div class="formItem">
                  <div class="formItemBg">
                    <p class="nameTitle">支付宝账号</p>
                    <van-field
                        v-model="form.zfbAccount"
                        name="pattern"
                        placeholder="请输入"
                        :rules="[{required: true,message: '请输入支付宝账号' }]"
                    />
                  </div>
                </div>
                <div class="sub">
                  <van-button round block type="info" native-type="submit" @click="updatePayment">提交</van-button>
                </div>
              </van-form>
              <div class="status">
                <p>当前状态：{{ payment.paymentStatus }}</p>
                <div>{{payment.surplusMessage}}</div>

              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from ‘《组件路径》‘;
import headTop from "../../components/base/headTop.vue"
import userApi from "@/api/user"
import {Toast} from "vant";

export default {
//import引入的组件需要注入到对象中才能使用
  components: {
    headTop
  },
  data() {

    return {
      payment:{
        paymentStatus:'',
        surplusMessage:''
      },
    form:{
      "realname": "",
        "zfbAccount": ""
    },
      page: {
        pageNo: 1,
        pageSize: 10,
        weixin: ''
      },
      repeatflexFlag: false,
      taskconFlag: true,
      currentTag: 0,
      taskList: [
        {
          title: '我的推广',
        },
        {
          title: '299奖励',
        }
      ],
      list: [],
      value1: '',
      value2: '',
      pattern: /\d{6}/,
      loading: false,
      finished: false,
    };
  },
//监听属性 类似于data概念
  computed: {},
//监控data中的数据变化
  watch: {},

  methods: {
    clickTitle(name) {
      this.currentTag = name
      if (name == 1) {
        this.repeatflexFlag = true
        this.taskconFlag = false
        this.page.pageNo = 1
        this.page.weixin = ''
        this.recommendList()
      } else {
        this.repeatflexFlag = false
        this.taskconFlag = true
      }
      this.finished = false;
    },
    query() {
      this.recommendList()
    },
    onFailed(event) {
    },
    recommendList() {
      userApi.recommendList(this.page).then(res => {
        this.list = res.data.records
      })
    },
    recommendStatus(){
      userApi.recommendStatus().then(res=>{
        this.payment = res.data.record
      })
    },
    updatePayment(){ // 退会费
      userApi.updatePayment(this.form).then(res=>{
        Toast(res.message)
        this.recommendStatus()
      })
    },

    onLoad() {
      this.page.pageNo += 1
      userApi.recommendList(this.page).then(res=>{
        console.log(res)
        var tal = res.data.pages
        this.list = this.list.concat(res.data.records)
        this.loading = false;
        if(tal == 1){
          this.page.pageNo = 1
        }
        if(this.page.pageNo == tal){
          this.finished = true;
          this.page.pageNo =1
        }

      })
    },
  },

  created() {
    this.recommendList()
    this.recommendStatus()
  },

  mounted() {

  },
  beforeCreate() {
  },
  beforeMount() {
  },
  beforeUpdate() {
  },
  updated() {
  },
  beforeDestroy() {
  },
  destroyed() {
  },
  activated() {
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang="less" scoped>
.recommend {
  width: 100%;
  min-height: 100%;
  background: #f8f8f8;
}

.vantTabs {
  width: 100%;

  /deep/ .van-tabs__line {
    width: 50%;
    background: #f8f5be;
  }

  /deep/ .van-sticky {
    width: 100%;
    position: fixed;
    top: 50px;
    left: 0;
  }

  /deep/ .van-tab {
    font-size: 17px;
    font-weight: bold;
  }

  .search {
    width: 100%;
    background: white;
    position: fixed;
    top: 94px;
    left: 0;

    .searchpd {
      padding: 10px;
      display: flex;
      align-items: center;

      input {
        flex: 1;
        text-indent: 20px;
        background: #f4f4f4;
        border-radius: 5px;
        height: 30px;
        line-height: 30px;
      }

    }
  }

  .taskcon {
    width: 100%;
    background: white;

    .taskconmsg {
      width: 96.55%;
      margin: 0 auto;

      .title {
        text-align: center;
        padding: 10px 0;
      }

      .item {
        padding: 10px 5px;
        border-radius: 5px;
        background: #f7fbfe;
        margin-bottom: 5px;
        box-shadow: 0px 6px 7px 0px #e5e5e5;

        ul {
          width: 100%;

          li {
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
            align-items: center;
            font-size: 12px;
            color: #727271;

            .reslut {
              color: black;
              font-size: 14px;
            }
          }
        }
      }

      .repeatflex {
        display: flex;
        justify-content: space-between;
        margin-bottom: 5px;

        div {
          width: 49.8%;
          text-align: center;
          padding: 5px 0;
        }

        .repeat {
          background: #abdbe7;
        }

        .colse {
          background: #f8f5be;
        }
      }
    }

    .editorCon {
      width: 100%;
      background: #ffffff;
      font-size: 14px;

      ul {
        li {
          border-bottom: 1px solid #e8e8e8;

          .editorConLis {
            padding: 10px;
            display: flex;
            align-items: center;

            .nameTitle {
              width: 100px;
              color: #949ba2;
              line-height: 30px;
            }

            .ipt {
              flex: 1;

              input {
                width: 100%;
                height: 30px;

              }
            }

          }

          .selectWork {
            .ipt {
              .select {
                height: 30px;
                width: 100%;
                border: 0;
                background: #ffffff;
              }
            }
          }
        }
      }

      .formItem {
        width: 100%;
        border-bottom: 1px solid #e8e8e8;

        .formItemBg {
          display: flex;
          align-items: center;
          flex-wrap: nowrap;
          padding: 10px;
          line-height: 30px;

          /deep/ .van-field {
            flex: 1;
          }

          .nameTitle {
            width: 100px;
            color: #949ba2;
            line-height: 30px;
          }

          .ipt {
            flex: 1;
            padding-left: 20px;

            .select {
              width: 100%;
              height: 30px;
              border: none;

              option {
                height: 30px;
              }
            }
          }

          /deep/ .van-cell {
            padding: 0px;

            input {
              text-indent: 20px;
              height: 30px;
            }
          }

        }

      }

      .sub {
        width: 100%;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #ffffff;
        padding-bottom: 10px;
        /deep/.van-button--info{
          color: black;
        }
        .van-button {
          width: 95%;
          margin: 0 auto;
          background: #f8f5be;
          border: none;
        }
      }

      .status {
        width: 100%;
        text-align: center;
      }
    }
  }
}

/*.resetBut {*/
/*  width: 100%;*/
/*  background: white;*/
/*  position: fixed;*/
/*  left: 0;*/
/*  bottom: 0;*/
/*  padding-bottom: 10px;*/

/*  .button {*/
/*    color: white;*/
/*    margin: 0 auto;*/
/*    width: 90%;*/
/*    border-radius: 30px;*/
/*    height: 40px;*/
/*    line-height: 40px;*/
/*    text-align: center;*/
/*    background: #f8f5be;*/
/*  }*/

/*}*/

</style>
